import java.util.HashMap;
import java.util.Map;

public class Solution12 {
    //1218. 最长定差子序列
    public int longestSubsequence(int[] arr, int difference) {
        Map<Integer,Integer> hash = new HashMap<>();  //arr[i]  dp[i]
        int ret = 1;
        for (int a : arr) {
            hash.put(a,hash.getOrDefault(a-difference,0)+1);
            ret = Math.max(ret,hash.get(a));
        }
        return ret;
    }
}
